import 'package:chop/Model/address_entity.dart';
import 'package:chop/common/StringUtils.dart';
import 'package:chop/view/map/New_location.dart';
import 'package:chop/view/sendyou/send_address_page.dart';
import 'package:chop/widgets/TextSizeWidget.dart';
import 'package:chop/widgets/Textwidget.dart';
import 'package:chop/widgets/ToastWidget.dart';
import 'package:chop/widgets/appBar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class Pickupaddress_job extends StatefulWidget {
  @override
  _Pickupaddress_jobState createState() => _Pickupaddress_jobState();
}

class _Pickupaddress_jobState extends State<Pickupaddress_job> {
  TextEditingController _address; //地址
  TextEditingController _specific_floor_number; //具体门牌号
  TextEditingController _telephone_number; //发货人电话
  TextEditingController _specific_name; //发货人姓名
  TextEditingController _remarks; //备注

  AdrEntityData data;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _address = TextEditingController();
    _specific_floor_number = TextEditingController();
    _telephone_number = TextEditingController();
    _specific_name = TextEditingController();
    _remarks = TextEditingController();
  }

  @override
  int choose; //选择是否有人接受货物
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BaseViewBar(
          childView: BaseTitleBar("请完成您收件的地址"),
          preferredSize: Size.fromHeight(50.0),
        ),
        body: Stack(
          children: <Widget>[
            ListView(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.all(20),
                  child: Column(
                    children: <Widget>[
                      TextOpenMap(
                        controller: _address,
                        helperText: "请在地图上选取送达地址",
                        labelText: "address",
                        click: () async {
                          data = await Get.to(NewLocation());
                          if(data != null){
                            _address.text = data.address;
                            print("____________<${data.address}");
                          }
                        },
                        btnClick: () async {
                          data = await Get.to(sendAddressPage(isSend: false,));
                          if(data!=null){
                            _address.text = data.address;
                            _specific_floor_number.text = data.remark;
                            _telephone_number.text = data.phone;
                            _specific_name.text = data.name;

                          }
                        },
                      ),
                      TextWidget(
                        controller: _specific_floor_number,
                        labelText: "Specific_floor_number",
                        helperText: "请填写详细门牌号",
                      ),
                      TextWidget(
                        controller: _telephone_number,
                        labelText: "Specific telephone number",
                        helperText: "如有人接收请填写电话号码（选填）",
                      ),
                      TextWidget(
                        controller: _specific_name,
                        labelText: "Specific_name",
                        helperText: "如有人接收请填写对方姓名（选填）",
                      ),
                    ],
                  ),
                ),
              ],
            ),
            Positioned(
              bottom: 0,
              width: MediaQuery.of(context).size.width,
              child: Container(
                child: Row(
                  children: <Widget>[
                    Expanded(
//                      flex: 7,
                      child: RaisedButton(
                        //提交按钮
                        color: Colors.lightBlueAccent,
                        highlightColor: Colors.blueAccent,
                        splashColor: Colors.blue,
                        colorBrightness: Brightness.dark,
//                        shape: RoundedRectangleBorder(
//                          //四角圆角
//                            borderRadius: BorderRadius.circular(10)),
                        onPressed: () {
                          if (StringUtils.isNull(_address.text)) {
                            return Toast.toast(context,
                                msg: "请填写收货地址", position: ToastPostion.bottom);
                          } else if (StringUtils.isNull(
                              _telephone_number.text)) {
                            return Toast.toast(context,
                                msg: "请填写手机号码", position: ToastPostion.bottom);
                          } else if (StringUtils.isNull(_specific_name.text)) {
                            return Toast.toast(context,
                                msg: "请填写收货人姓名", position: ToastPostion.bottom);
                          } else {
                            data.address = _address.text.trim();
                            data.remark = _specific_floor_number.text.trim();
                            data.phone = _telephone_number.text.trim();
                            data.name = _specific_name.text.trim();
                            Get.back(result: data);
                          }
                        },
                        child: FixedSizeText(
                          '提交地址',
                          style: TextStyle(color: Colors.white, fontSize: 15),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ));
  }

//  void updatechoose(int v){
//    setState(() {
//      choose=v;
//      print(v);
//    });
//  }
}
